home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Education et Sciences / Mathématiques / Matt's_Fract 1.05 / Sources / fractal.c next >
C/C++ Source or Header  |  1995-11-17  |  34KB  |  1,609 lines

  1. #include "AllTools.h"
  2. #include "fractal.h"
  3.  
  4. #define NIL_POINTER       0L
  5. #define REMOVE_ALL_EVENTS 0
  6.  
  7. #define    mrBlob1    ((x >> 8) & 255) + (y & 65280)
  8. #define    mrBlob2    ((x >> 8) & 254) + (y & 65024)
  9. #define    mrBlob3    ((x >> 8) & 252) + (y & 64512)
  10. #define heightShift 7
  11.  
  12. void     Maketables(void);
  13. void     ToolBoxInit(void);
  14. void     WindowInit(void);
  15. void    MemInit(void);
  16. void    MemEnd(void);
  17. void     FillWindowsBlack( void );
  18. void    WindowMove(void);
  19.  
  20. #if GENERATING68K
  21.     asm        copyOffScreen(void);
  22.     asm     clearOffScreen(void);
  23. #else
  24.     void    copyOffScreen(void);
  25.     void     clearOffScreen(void);
  26. #endif
  27.  
  28. void     ToDrawX1(void);
  29. void     ToDrawX2(void);
  30. void     ToDrawX4(void);
  31.  
  32. void     DoPreferences(void);
  33. void    DoOther(void);
  34. void    MakeMap(void);
  35. void     ChangeHeight( int pss, int height );
  36. void    Smooth(int pss);
  37. void     MakeCols(void);
  38. void     BlurMap(void);
  39. void    Quit(void);
  40. int        hght(short x, short y);
  41. int     hght2(short x, short y);
  42. void    fixVars(void);
  43.  
  44. typedef struct
  45.     {
  46.         unsigned char    map[256][256];
  47.     }  MAP, *mapPeek;
  48.  
  49. typedef struct
  50.     {
  51.         unsigned long    colorGrid[256][512];
  52.     } aCol,    *aColPeek;
  53.  
  54. WindowPtr             BackWindow, theGameWindow;
  55. PaletteHandle        fracCols;
  56. Ptr                    offScreen;
  57. Ptr theTemp, theTemp2, theTemp3;
  58. videoInfo    theScreen;
  59. Ptr ScrnBase;
  60.  
  61. long    hhhh, xxxx, yyyy, cxxxx, cyyyy;
  62. long    mapX, mapY, mapXp, mapYp;
  63. long    windX, windY, rayLen, xStep, yStep, windX2, windY2, windX4, windXstep, windYsteps, yOffSet;
  64. long    cs[2560], sn[2560], angle;
  65. long    theSize;
  66. long    rBts, xres2, yres2, orfset;
  67. long    randSeed, waterLevel;
  68.  
  69. long    velocity;
  70. short    pNum;
  71. mapPeek    the, the2;
  72. aColPeek the3;
  73. short    oldBitDepth;
  74. long    tempHeight;
  75.  
  76. short    RayLengthOption, PixelSizeOption, LandScapeOption, WindowSizeOption;
  77.  
  78. long    mx2, my2, scale;
  79.  
  80. long    keyBoard, maxHeight, roughness;
  81.  
  82. void main( void )
  83. {
  84. Point    tmpMouse;
  85. KeyMap    theKeys;
  86. Boolean anEvent, intEnd;
  87. EventRecord    theEvent;
  88.  
  89. MbarInit();
  90.  
  91. RayLengthOption = 6;
  92. PixelSizeOption = 4;
  93. LandScapeOption = 6;
  94. WindowSizeOption = 4;
  95. maxHeight = 2;
  96. roughness = 2;
  97. keyBoard = control_is_mouse;
  98.  
  99. pNum    =    8;
  100.  
  101. windX     =     256;
  102. windY     =     192;
  103. rayLen    =    511;
  104. xStep    =    4;
  105. yStep    =    2;
  106.  
  107. waterLevel=    0;
  108.  
  109. mapX    =    256;
  110. mapY    =    256;
  111. mapXp    =    mapX - 1;
  112. mapYp    =    mapY - 1;
  113.  
  114.     ToolBoxInit();
  115.  
  116.     qd.randSeed = (unsigned long)TickCount();
  117.     randSeed = Random() + 32767;
  118.     if (randSeed == 0) randSeed = 1;
  119.  
  120.     HideMenuBar();
  121.     WindowInit();
  122.     MemInit();
  123.     Maketables();
  124.  
  125. fixVars();
  126.  
  127. // Scale is used to stadardise movement using the mouse on larger screens.
  128. scale = (long)(theScreen.resolutionX);
  129.  
  130.     while(TRUE)
  131.     {
  132.         DoPreferences();
  133.         
  134.         fixVars();    
  135.         WindowMove();
  136.  
  137.         MakeMap();
  138.         BlurMap();
  139.         MakeCols();
  140.  
  141.         if ( keyBoard == control_is_keys ) { mx2 = xres2; my2 = yres2; }
  142.  
  143.         clearOffScreen();
  144. hhhh = ((long)(the->map[(short)((yyyy >> 8) & 255)][(short)((xxxx >> 8) & 255)] + 4) << heightShift);
  145.  
  146. intEnd = FALSE;
  147.  
  148.             while( intEnd == FALSE )
  149.             {
  150.             anEvent = GetNextEvent( 0xffff, &theEvent );
  151.             GetKeys( theKeys );
  152.  
  153.                 if ( keyBoard == control_is_mouse )
  154.                         {
  155.                             // Get and standardise the mouse position.
  156.                             GetMouse( &tmpMouse);
  157.                             mx2 = ((long)tmpMouse.h * scale) >> 9;
  158.                             my2 = ((long)tmpMouse.v * scale) >> 9;
  159.                         }
  160.  
  161.                 if ( keyBoard == control_is_keys )
  162.                         {
  163.                             if ( ((theKeys[3] >> 3) & 0x01) == TRUE )    mx2 -= 32;
  164.                             if ( ((theKeys[3] >> 4) & 0x01) == TRUE )    mx2 += 32;
  165.                             if ( ((theKeys[3] >> 6) & 0x01) == TRUE )    my2 -= 32;
  166.                             if ( ((theKeys[3] >> 5) & 0x01) == TRUE )    my2 += 32;
  167.                             
  168.                             if ( mx2 > 512 ) mx2 = 512;
  169.                             if ( mx2 <   0 ) mx2 =   0;
  170.                             if ( my2 > 440 ) my2 = 440;
  171.                             if ( my2 <   0 ) my2 =   0;
  172.                         }
  173.  
  174.     // This part checks if you have pushed enter/space or the mouse button thus ending current flight
  175.     if ( (theKeys[1] >>  9) & 0x01 == TRUE ) intEnd = TRUE; // space
  176.     if ( (theKeys[1] >> 28) & 0x01 == TRUE ) intEnd = TRUE; // enter
  177.     if ( Button() == TRUE ) intEnd = TRUE; // mouse button
  178.     
  179.     // Adjust you velocity due to key presses.
  180.     if ( ((theKeys[0] >> 0) & 0x01) == TRUE )    velocity += 128; // key pressed is +
  181.     if ( ((theKeys[0] >> 3) & 0x01) == TRUE )    velocity -= 128; // key pressed is -
  182.     
  183.     // Adjust the angle you are looking in.
  184.     angle -= ((xres2 - mx2) >> 3);
  185.     if ( angle > 2559 )    angle -= 2560;
  186.     if ( angle <   0 )    angle += 2560;
  187.  
  188.     if ( ( theKeys[1] & 0x01 ) == FALSE ) // Is shift pressed?
  189.         {                                  // No, then direction and height can change.
  190.             hhhh -= ((yres2 - my2));      // This line changes your altitude.  
  191.             cxxxx = ((cs[angle] * velocity) >> 8);
  192.             cyyyy = ((sn[angle] * velocity) >> 8);
  193.         }
  194.  
  195.         // Move you around in the x,y plane.
  196.         xxxx += cxxxx;
  197.         yyyy += cyyyy;
  198.  
  199.         yOffSet = (yres2 - my2) >> 1;
  200.  
  201. // These lines make sure you don't go underground.
  202. tempHeight = ((long)(the->map[(short)((yyyy >> 8) & 255)][(short)((xxxx >> 8) & 255)] + 4) << heightShift);
  203. if (hhhh < tempHeight) hhhh = tempHeight;
  204.                 
  205.                 // Call the drawing routines.
  206.                 if (xStep == 1) ToDrawX1();
  207.                 if (xStep == 2) ToDrawX2();
  208.                 if (xStep == 4) ToDrawX4();
  209.             }
  210.     }
  211. }
  212.  
  213. void fixVars(void)
  214. {
  215.     angle    =    0;
  216.     rBts    =    (long)(theScreen.rowBytes);
  217.     xres2    =    (long)((theScreen.resolutionX) >> 1);
  218.     yres2    =    (long)((theScreen.resolutionY) >> 1);
  219.     theSize    =    windX * windY;
  220.     orfset    = (xres2 - windX) + ((yres2 - windY) * rBts);
  221.     windX2    =    windX << 1;
  222.     windY2    =    windY << 1;
  223.     windX4    =    windX2 << 1;
  224.     windYsteps = windY2 / yStep;
  225.     windXstep = yStep * windX2;
  226.     velocity = 256;
  227. }
  228.  
  229. void Maketables(void)
  230. {
  231. long    cnt;
  232. float    num;
  233.     
  234. long colr, shady, depth;
  235. long colorPtr;
  236. long shaded, shaded2;
  237.  
  238. DialogPtr    dialog;
  239.     
  240. dialog = GetNewDialog(134, nil, (WindowPtr)-1);
  241. DrawDialog(dialog);
  242.  
  243. // Make cosing and sine tables.
  244. for (cnt = 0; cnt < 2560; cnt++ )
  245.     {
  246.     num    = (float)cnt * 0.00245436926062;
  247.     cs[cnt] = (long)(cos(num) * 256);
  248.     sn[cnt] = (long)(sin(num) * 256);
  249.     }
  250.  
  251. the3 = (aColPeek)theTemp3;
  252.  
  253. // Make color tables.
  254. for (colr = 0;colr < 16; colr++)
  255. {
  256.     for (shady = 0;shady < 16; shady++)
  257.     {
  258.         colorPtr = (colr << 4) + shady;
  259.         for (depth = 0;depth < rayLen; depth ++)
  260.         {
  261.             shaded  = ((shady << 2) - ((shady  * depth) >> 7));
  262.             shaded2 = shaded & 1;  //Shaded2 is used for dithering
  263.             shaded  = shaded >> 1;
  264.             shaded2 += shaded;
  265.             if (shaded2 > 31) shaded2 = 31;
  266.  
  267.             shaded  += ( colr << 5 );
  268.             shaded2 += ( colr << 5 );
  269.             
  270.             shaded += ( shaded2 << 8 );
  271.             shaded += ( shaded << 16 );
  272.             the3->colorGrid[(short)colorPtr][(short)depth] = (unsigned long)shaded;
  273.         }
  274.     }
  275. }
  276.  
  277. DisposDialog(dialog);
  278.  
  279. }
  280.  
  281. void ToolBoxInit(void)
  282. {
  283.     InitGraf(&qd.thePort);
  284.     InitFonts();
  285.     FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  286.     InitWindows();
  287.     InitMenus();
  288.     TEInit();
  289.     InitDialogs(NIL_POINTER);
  290.     InitCursor();
  291.     
  292.     theScreen = GetVideoInfo();
  293.     ScrnBase = theScreen.screenBase;
  294. }
  295.  
  296. void WindowInit(void)
  297. {
  298. DialogPtr    dialog;
  299. Boolean    itsDone;
  300. short    itemHit;
  301. Rect    theRect, theGameRect;
  302.  
  303. oldBitDepth = theScreen.bitsPerPixel;
  304.  
  305.     if (theScreen.BitDepthPossible[8] == FALSE) DoError( 17, TRUE); // Am I in an 8bit mode?
  306.  
  307.     // Can I do an 8bit mode? and if so can I change?
  308.     if ((theScreen.bitsPerPixel != 8) && (theScreen.BitDepthPossible[8] == TRUE))
  309.                             {
  310.                                 SysBeep(1);
  311.                                 dialog = GetNewDialog(132, nil, (WindowPtr)-1);
  312.                                 if (dialog == 0) DoError(4 ,TRUE);
  313.                                 SetPort( dialog );
  314.                                 DrawDialog(dialog);
  315.                                 PenMode( 0 );
  316.                                 PenSize( 3, 3 );
  317.                                 theRect = GetDRect( dialog, 5 );
  318.                                 FrameRoundRect( &theRect, 16, 16 );
  319.                                 
  320. itsDone = FALSE;
  321. FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  322.             while(!itsDone)
  323.             {
  324.                 ModalDialog(nil, &itemHit);
  325.                 if (itemHit == 1)     {
  326.                                     ChangeBitDepth(8,1);
  327.                                     theScreen = GetVideoInfo();
  328.                                     itsDone = TRUE;
  329.                                     }
  330.                                     
  331.                 if (itemHit == 2)     {
  332.                                     ExitToShell();
  333.                                     }
  334.                             }
  335.             DisposDialog(dialog);
  336.             }
  337.  
  338.     // Lets open some windows starting with the background then the foreground.
  339.     BackWindow = NewCWindow( 0L, &theScreen.screenRect, "\pFractal", TRUE, plainDBox, ( WindowPtr ) -1, FALSE, 0L );
  340.     SelectWindow(BackWindow);
  341.     SetPort(BackWindow);
  342.     
  343. SetRect(&theGameRect, 0, 0, (windX << 1), (windY << 1));
  344.  
  345.     theGameWindow = NewCWindow(nil, &theGameRect, "\pFractal", TRUE, 1, (WindowPtr)-1, FALSE, 0);
  346.     MoveWindow(theGameWindow,     (theScreen.resolutionX >>1) - windX, 
  347.                                 (theScreen.resolutionY >>1) - windY, FALSE);
  348.  
  349.     FillWindowsBlack( );
  350.  
  351.     fracCols = GetNewPalette( (127 + pNum) );
  352. }
  353.  
  354. void    WindowMove(void)
  355. {
  356. Rect theGameRect;
  357.  
  358.     qd.randSeed = randSeed;
  359.     
  360.     SelectWindow(BackWindow);
  361.     SetPort(BackWindow);
  362.     
  363.     SetRect( &theGameRect, 0, 0, (windX << 1), (windY << 1) );
  364.     SizeWindow( theGameWindow, (windX << 1), (windY << 1), TRUE );
  365.  
  366.     MoveWindow(theGameWindow,     (theScreen.resolutionX >>1) - windX, 
  367.                                 (theScreen.resolutionY >>1) - windY, FALSE );
  368.  
  369.     DisposePalette(fracCols);
  370.     fracCols = GetNewPalette( (127 + pNum) );
  371.     SetPalette( BackWindow, fracCols, TRUE );
  372.     SetPalette( theGameWindow, fracCols, TRUE );
  373.     
  374.     FillWindowsBlack( );
  375.  
  376.     SelectWindow(theGameWindow);
  377.     SelectWindow(theGameWindow);
  378. }
  379.  
  380. void MemInit(void)
  381. {
  382. Size    ScSize;
  383.  
  384.     theTemp        =     NewPtr( 66049 );
  385.     if (theTemp == 0) DoError(6, TRUE);
  386.  
  387.     theTemp2    =     NewPtr( 66049 );
  388.     if (theTemp2 == 0) DoError(6, TRUE);
  389.  
  390. ScSize = (Size)(((long)theScreen.resolutionX) * ((long)theScreen.resolutionY));
  391.  
  392.     offScreen    =    NewPtr( ScSize );
  393.     if (offScreen == 0) DoError(6, TRUE);
  394.     
  395.     theTemp3 = NewPtr( 524288 );
  396.     if (theTemp3 == 0) DoError(6, TRUE);
  397.     
  398.     the = (mapPeek)theTemp;
  399.     the2 = (mapPeek)theTemp2;
  400. }
  401.  
  402. void MemEnd(void)
  403. {
  404.     DisposPtr(theTemp);
  405.     DisposPtr(theTemp2);
  406.     DisposPtr(theTemp3);
  407.     DisposPtr(offScreen);
  408. }
  409.  
  410. void FillWindowsBlack( void )
  411. {
  412.     SetPort(BackWindow);
  413.     ForeColor( blackColor );
  414.     PaintRect( &BackWindow->portRect );
  415.     SetPort(theGameWindow);
  416.     ForeColor( blackColor );
  417.     PaintRect( &theGameWindow->portRect );
  418. }
  419.  
  420. void MakeMap(void)
  421. {
  422.     short     pss,height;
  423.     short        x,y;
  424.     
  425.     DialogPtr    dialog;
  426.  
  427.     dialog = GetNewDialog(129, nil, (WindowPtr)-1);
  428.     DrawDialog(dialog);
  429.     FillWindowsBlack( );
  430.  
  431.     qd.randSeed = randSeed;
  432.         
  433.     pss =        64;
  434.     height =    128;
  435.     
  436.     for( y = 0; y < mapY; y++ )
  437.     {
  438.         for( x = 0; x < mapX; x++ )
  439.         {
  440.             the->map[x][y] = 128;
  441.         }
  442.     }
  443.                 
  444.     while( pss > ( 20 - ( 4 * roughness ) ) )
  445.     {
  446.         ChangeHeight( pss, height );
  447.         Smooth(pss);
  448.         pss = pss >> 1;
  449.         height = height >> 1;
  450.         if (height == 0) height = 1;
  451.     }
  452.     
  453.     while(pss > 1)
  454.     {
  455.         Smooth(pss);
  456.         pss = pss >> 1;
  457.     }
  458.  
  459.     DisposDialog(dialog);
  460. }
  461.  
  462. void ChangeHeight( int pss, int height )
  463. {
  464.     long            x,y;
  465.  
  466.     for ( x = 0; x < mapX; x = x + pss )
  467.     {
  468.         for( y = 0; y < mapY; y = y + pss )
  469.         {
  470.             the->map[x][y] = the->map[x][y] + (((long)Random() * height) >> (17 - maxHeight) );
  471.         }
  472.     }
  473.     
  474. }
  475.  
  476. void Smooth(int pss)
  477. {
  478.     long        dff;
  479.     short        x,y;
  480.     long    misc;
  481.  
  482.     dff = pss>>1;
  483.     for ( x = 0; x < mapX; x = x + pss )
  484.     {
  485.         for( y = 0; y < mapY; y = y + pss )
  486.         {    
  487.         
  488.     misc = (long)((long)hght(x,y) + (long)hght(x + pss,y) + (long)hght(x + pss,y + pss) + (long)hght(x,y + pss));
  489.     
  490.     the->map[x+dff][y+dff] = (unsigned char)(misc >> 2);
  491.     
  492.     the->map[x+dff][y] = (hght(x,y) + hght(x+pss,y)) >> 1;
  493.     
  494.     the->map[x][y+dff] = (hght(x,y) + hght(x,y+pss)) >> 1;
  495.  
  496.     the->map[x+pss][y+dff] = ((long)((hght(x+pss,y+pss) + hght(x+pss,y)))) >> 1;
  497.  
  498.     the->map[x+dff][y+pss] = ( hght(x+pss,y+pss) + hght(x,y+pss)) >> 1;
  499.             
  500.         }
  501.     }
  502. }
  503.  
  504. int hght(short x, short y)
  505. {
  506.  
  507. return (unsigned char)the->map[x & mapXp][y & mapYp];
  508. }
  509.  
  510. int hght2(short x, short y)
  511. {
  512.  
  513. return (unsigned char)the2->map[x & mapXp][y & mapYp];
  514. }
  515.  
  516. void BlurMap(void)
  517. {
  518. long    hht;
  519. short    x,y;
  520.  
  521.     DialogPtr    dialog;
  522.     
  523.     dialog = GetNewDialog(130, nil, (WindowPtr)-1);
  524.     DrawDialog(dialog);
  525.     FillWindowsBlack( );
  526.  
  527. for(x = 0; x < mapX; x++)
  528.     {
  529.         for(y = 0; y < mapY; y++)
  530.             {
  531.                 hht = the->map[x][y];
  532.                 
  533.                 hht -= waterLevel;
  534.                 if (hht < 0) hht = 0;
  535.                 the2->map[x][y] = hht;
  536.             }
  537.     }
  538.  
  539. for(x = 0; x < mapX; x++)
  540.     {
  541.         for(y = 0; y < mapY; y++)
  542.             {
  543.                 hht = (long)(((long)hght2(x+6,y-4)) << 2) + (((long)hght2(x-4,y+8)) << 2) + ((long)(hght2(x,y)) << 3);
  544.                 the->map[x][y] = (unsigned char)(hht >> 5);
  545.             }
  546.     }
  547.  
  548.     DisposDialog(dialog);
  549. }
  550.  
  551. void MakeCols(void)
  552. {
  553.     short    x, y, c, co;
  554.     
  555.     DialogPtr    dialog;
  556.     
  557.     dialog = GetNewDialog(131, nil, (WindowPtr)-1);
  558.     DrawDialog(dialog);
  559.     FillWindowsBlack( );
  560.     
  561.     for( y = 0; y < mapX; y++)
  562.     {
  563.         for( x = 0; x < mapY; x++)
  564.         {
  565.             c = (short)(the->map[x][y]);
  566.             co = c;
  567.                 c = (short)( (long)(c - 
  568.                             ((unsigned char)the->map
  569.                                 [((short)(x + 3) & mapXp)]
  570.                                 [((short)(y + 3) & mapYp)])
  571.                         ));
  572.                  c = (c >> 1) + 7;
  573.                  if (c > 15) c = 15;
  574.                  if (c < 0) c = 0;
  575.                  
  576.                  c += 32;
  577.                  
  578.                  if (co == 0) c = 47;
  579.                  if (co > 0) c = c + 16;
  580.                  if (co > 16) c = c + 16;
  581.                  if (co > 32) c = c + 16;
  582.                  if (co > 48) c = c + 16;
  583.                                   
  584.                  the2->map[x][y] = (unsigned char)(c);
  585.         }
  586.     }
  587.  
  588.     DisposDialog(dialog);
  589.     FillWindowsBlack( );
  590. }
  591.  
  592. #if GENERATING68K
  593.  
  594. asm copyOffScreen(void)
  595. {
  596.     move.l    offScreen, a0
  597.     add.l    windXstep, a0
  598.     sub.l    windX2, a0
  599.     move.l    ScrnBase, a1
  600.     add.l    orfset, a1
  601.     
  602.     move.l    windYsteps, d1
  603.     move.l    windX, d0
  604.     asr.l    #1, d0
  605.     sub.l    #1, d0
  606.     sub.l    #1, d1
  607.     
  608.     asr        #2, d0
  609.     move.l    d0, d2
  610.  
  611.     move.l    rBts, d3
  612.     sub.l    windX2, d3
  613.  
  614.     @4:
  615.     move.l    yStep, d7
  616.     sub.l    #1, d7
  617.     
  618.         @50:
  619.         move.l    d2, d0
  620.                 
  621.             @5:
  622.             move.l    (a0)+, (a1)+
  623.             move.l    (a0)+, (a1)+
  624.             move.l    (a0)+, (a1)+
  625.             move.l    (a0)+, (a1)+
  626.             dbra    d0, @5
  627.     
  628.         sub.l    windX2, a0    /* for copy same line */
  629.         add.l    d3, a1        /* where d3 is diff. between windowXsize and RowBytes */
  630.     
  631.         dbra    d7,@50    
  632.  
  633.     add.l    windXstep, a0
  634.     dbra    d1,@4
  635.     
  636. rts
  637. }
  638.  
  639. #else
  640.  
  641. void copyOffScreen(void)
  642. {
  643. Ptr    ta0, ta1, ta2;
  644. long td0, td1, td2, td3, td7;    
  645.  
  646. ta0 = offScreen;
  647. ta0 += windXstep;
  648. ta0 -= windX2;
  649. ta1 = ScrnBase;
  650. ta1+= orfset;
  651.  
  652. td1 = windYsteps;
  653. td0 = (windX >> 1);
  654. td0 -= 1;
  655. td1 -= 1;
  656.  
  657. td2 = td0;
  658.  
  659. td3 = rBts - windX2;
  660.  
  661. while(td1 >= 0)
  662.     {
  663.         td7 = yStep - 1;
  664.         
  665.         while(td7 >= 0)
  666.             {
  667.                 td0 = td2;
  668.                 
  669.                 ta2 = ta0 + (4 * td2);
  670.                 
  671.                 while(ta2 >= ta0)
  672.                     {
  673.                         *(unsigned long*)(ta1) = *(unsigned long*)(ta0);
  674.                         ta0 += 4;
  675.                         ta1 += 4;
  676.                     }
  677.                 ta0 -= windX2;
  678.                 ta1 += td3;
  679.                 
  680.                 td7 -= 1;
  681.             }
  682.         ta0 += windXstep;
  683.         td1 -= 1;
  684.     }
  685. }
  686.  
  687. #endif
  688.  
  689. #if GENERATING68K
  690.  
  691. asm clearOffScreen(void)
  692. {
  693.     move.l    offScreen, a0
  694.     move.l    theSize, d0
  695.     move.l    #514 , d1
  696.     move.l    d1, d2
  697.     swap    d2
  698.     add.l    d2, d1
  699.  
  700.     @1:
  701.     move.l    d1, (a0)+
  702.     move.l    d1, (a0)+
  703.     move.l    d1, (a0)+
  704.     move.l    d1, (a0)+
  705.     sub.l    #4, d0
  706.     bne    @1
  707.     rts
  708. }
  709.  
  710. #else
  711.  
  712. void clearOffScreen(void)
  713. {
  714. Ptr    offScreenCounter;
  715. Ptr    theEndCounter;
  716. unsigned long    skyColour;
  717.  
  718. offScreenCounter = offScreen;
  719. theEndCounter = offScreenCounter + (theSize << 2);
  720. skyColour = 514 + ( 514 << 16 );
  721.  
  722. while(theEndCounter != offScreenCounter)
  723.     {
  724.         *(unsigned long*)(offScreenCounter) = skyColour;
  725.         offScreenCounter +=4;
  726.     }
  727. }
  728.  
  729. #endif
  730.  
  731. void ToDrawX1(void)
  732. {
  733. long     xp, yp, xp2;
  734. long    L;
  735. long    x, y;
  736. long    xv, zv;
  737. long    z, yv;
  738. Ptr        offScreen2;
  739. unsigned short    MrBlobby;
  740. long    rayLenTmp;
  741. long    xOffSet, xOffSetdiv, xChng, yztemp, yOffSet2;
  742.  
  743. xp     = -windX;
  744. xp2    = 0;
  745. xChng = -((xres2 - mx2) >> 2);
  746. xOffSet = xp * xChng;
  747. xOffSetdiv = xOffSet >> 8;
  748.  
  749. while (xp < windX)
  750.     {
  751.  
  752.     x    =    xxxx;
  753.     y    =    yyyy;
  754.     z    =    hhhh + (xOffSet >> 8);
  755.  
  756.     yp    =     -windY;
  757.     L    =      0;
  758.     offScreen2 = offScreen + xp2 + (((windY2-1) * windX2));
  759.     
  760.     xv    =    (long)(cs[angle] - ((xp * sn[angle]) >> 8) );
  761.     zv    =    (long)(sn[angle] + ((xp * cs[angle]) >> 8) );
  762.  
  763.     yv    =    yp - yOffSet - (xOffSet >> 8);
  764.     yOffSet2 = - yOffSet - xOffSetdiv;
  765.  
  766.     rayLenTmp = 128;
  767.     if (rayLen < rayLenTmp) rayLenTmp = rayLen;
  768.     MrBlobby = mrBlob1;
  769.  
  770.     while (L<rayLenTmp)
  771.         {                        
  772.     
  773.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  774.             {
  775.             *(char*)(offScreen2) = 
  776.             *(char*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  777.  
  778.             yp += yStep;
  779.             if (yp >= windY) goto end3;    
  780.     
  781.             offScreen2    -= windXstep;
  782.             yv += yStep;
  783.  
  784.             z = hhhh + (yv * L);
  785.  
  786.             }
  787.             else
  788.             {
  789.                 L++;
  790.                 z += yv;
  791.                 x += xv;
  792.                 y += zv;
  793.                 MrBlobby = mrBlob1;
  794.             }
  795.         }
  796.         
  797.         yv    =    yv << 1;
  798.         xv    =    xv << 1;
  799.         zv    =    zv << 1;
  800.         
  801.         rayLenTmp = 256;
  802.         if (rayLen < rayLenTmp) rayLenTmp = rayLen;
  803.         
  804.         if (yp>=windY) L = rayLenTmp;
  805.  
  806.         yztemp = yp + yOffSet2;
  807.  
  808.         while ( L < rayLenTmp )
  809.         {
  810.  
  811.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  812.             {
  813.             *(char*)(offScreen2) = 
  814.             *(char*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  815.             
  816.             yp    += yStep;
  817.             if (yp >= windY) goto end3;
  818.                         
  819.             offScreen2    -= windXstep;
  820.  
  821.             yztemp += yStep;
  822.             yv = yztemp << 1;
  823.             
  824.             z = hhhh + (yztemp * L);
  825.  
  826.             }
  827.             else
  828.             {
  829.                 L += 2;
  830.                 x += xv;
  831.                 y += zv;
  832.                 z += yv;
  833.                 MrBlobby = mrBlob2;
  834.             }
  835.         }
  836.         
  837.         yv    =    yv << 1;
  838.         xv    =    xv << 1;
  839.         zv    =    zv << 1;
  840.         
  841.         rayLenTmp = rayLen;
  842.         
  843.         if (yp>=windY) goto end3;
  844.         
  845.         yztemp = yp + yOffSet2;
  846.  
  847.         while (L<rayLenTmp)
  848.         {
  849.  
  850.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  851.             {
  852.             *(char*)(offScreen2) = 
  853.             *(char*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  854.             
  855.             yp += yStep;
  856.             if (yp >= windY) goto end3;
  857.             
  858.             offScreen2    -= windXstep;
  859.                         
  860.             yztemp += yStep;
  861.             yv    =    yztemp << 2;
  862.             
  863.             z = hhhh + (yztemp * L);
  864.             }
  865.             else
  866.             {
  867.                 L += 4;
  868.                 x += xv;
  869.                 y += zv;
  870.                 z += yv;
  871.                 MrBlobby = mrBlob3;
  872.             }
  873.         }
  874.         
  875.     end3:
  876.     xp2    += 1;
  877.     xp    += 1;
  878.     xOffSet += xChng;
  879.     xOffSetdiv = xOffSet >> 8;
  880.     }
  881.     copyOffScreen();
  882.     clearOffScreen();
  883. }
  884.  
  885. void ToDrawX2(void)
  886. {
  887. long     xp, yp, xp2;
  888. long    L;
  889. long    x, y;
  890. long    xv, zv;
  891. long    z, yv;
  892. Ptr        offScreen2;
  893. unsigned short    MrBlobby;
  894. long    rayLenTmp;
  895. long    xOffSet, xOffSetdiv, xChng, yztemp, yOffSet2;
  896.  
  897. xp     = -windX;
  898. xp2    = 0;
  899. xChng = -((xres2 - mx2) >> 2);
  900. xOffSet = xp * xChng;
  901. xOffSetdiv = xOffSet >> 8;
  902. xChng = xChng << 1;
  903.  
  904. while (xp < windX)
  905.     {
  906.  
  907.     x    =    xxxx;
  908.     y    =    yyyy;
  909.     z    =    hhhh + (xOffSet >> 8);
  910.  
  911.     yp    =     -windY;
  912.     L    =      0;
  913.     offScreen2 = offScreen + xp2 + (((windY2-1) * windX2));
  914.     
  915.     xv    =    (long)(cs[angle] - ((xp * sn[angle]) >> 8) );
  916.     zv    =    (long)(sn[angle] + ((xp * cs[angle]) >> 8) );
  917.  
  918.     yv    =    yp - yOffSet - (xOffSet >> 8);
  919.     yOffSet2 = - yOffSet - xOffSetdiv;
  920.  
  921.     rayLenTmp = 128;
  922.     if (rayLen < rayLenTmp) rayLenTmp = rayLen;
  923.     MrBlobby = mrBlob1;
  924.  
  925.     while (L<rayLenTmp)
  926.         {                        
  927.     
  928.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  929.             {
  930.             *(short*)(offScreen2) = 
  931.             *(short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  932.  
  933.             yp += yStep;
  934.             if (yp >= windY) goto end3;    
  935.     
  936.             offScreen2    -= windXstep;
  937.             yv += yStep;
  938.  
  939.             z = hhhh + (yv * L);
  940.  
  941.             }
  942.             else
  943.             {
  944.                 L++;
  945.                 z += yv;
  946.                 x += xv;
  947.                 y += zv;
  948.                 MrBlobby = mrBlob1;
  949.             }
  950.         }
  951.         
  952.         yv    =    yv << 1;
  953.         xv    =    xv << 1;
  954.         zv    =    zv << 1;
  955.         
  956.         rayLenTmp = 256;
  957.         if (rayLen < rayLenTmp) rayLenTmp = rayLen;
  958.         
  959.         if (yp>=windY) L = rayLenTmp;
  960.  
  961.         yztemp = yp + yOffSet2;
  962.  
  963.         while ( L < rayLenTmp )
  964.         {
  965.  
  966.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  967.             {
  968.             *(short*)(offScreen2) = 
  969.             *(short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  970.             
  971.             yp    += yStep;
  972.             if (yp >= windY) goto end3;
  973.                         
  974.             offScreen2    -= windXstep;
  975.  
  976.             yztemp += yStep;
  977.             yv = yztemp << 1;
  978.             
  979.             z = hhhh + (yztemp * L);
  980.  
  981.             }
  982.             else
  983.             {
  984.                 L += 2;
  985.                 x += xv;
  986.                 y += zv;
  987.                 z += yv;
  988.                 MrBlobby = mrBlob2;
  989.             }
  990.         }
  991.         
  992.         yv    =    yv << 1;
  993.         xv    =    xv << 1;
  994.         zv    =    zv << 1;
  995.         
  996.         rayLenTmp = rayLen;
  997.         
  998.         if (yp>=windY) goto end3;
  999.         
  1000.         yztemp = yp + yOffSet2;
  1001.  
  1002.         while (L<rayLenTmp)
  1003.         {
  1004.  
  1005.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  1006.             {
  1007.             *(short*)(offScreen2) = 
  1008.             *(short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  1009.             
  1010.             yp += yStep;
  1011.             if (yp >= windY) goto end3;
  1012.             
  1013.             offScreen2    -= windXstep;
  1014.                         
  1015.             yztemp += yStep;
  1016.             yv    =    yztemp << 2;
  1017.             
  1018.             z = hhhh + (yztemp * L);
  1019.             }
  1020.             else
  1021.             {
  1022.                 L += 4;
  1023.                 x += xv;
  1024.                 y += zv;
  1025.                 z += yv;
  1026.                 MrBlobby = mrBlob3;
  1027.             }
  1028.         }
  1029.     
  1030.     end3:
  1031.     xp2    += 2;
  1032.     xp    += 2;
  1033.     xOffSet += xChng;
  1034.     xOffSetdiv = xOffSet >> 8;
  1035.     }
  1036.     copyOffScreen();
  1037.     clearOffScreen();
  1038. }
  1039.  
  1040. void ToDrawX4(void)
  1041. {
  1042. long     xp, yp, xp2;
  1043. long    L;
  1044. long    x, y;
  1045. long    xv, zv;
  1046. long    z, yv;
  1047. Ptr        offScreen2;
  1048. unsigned short    MrBlobby;
  1049. long    rayLenTmp;
  1050. long    xOffSet, xOffSetdiv, xChng, yztemp, yOffSet2;
  1051.  
  1052. xp     = -windX;
  1053. xp2    = 0;
  1054. xChng = -((xres2 - mx2) >> 2);
  1055. xOffSet = xp * xChng;
  1056. xOffSetdiv = xOffSet >> 8;
  1057. xChng = xChng << 2;
  1058.  
  1059. while (xp < windX)
  1060.     {
  1061.  
  1062.     x    =    xxxx;
  1063.     y    =    yyyy;
  1064.     z    =    hhhh + (xOffSet >> 8);
  1065.  
  1066.     yp    =     -windY;
  1067.     L    =      0;
  1068.     offScreen2 = offScreen + xp2 + (((windY2-1) * windX2));
  1069.     
  1070.     xv    =    (long)(cs[angle] - ((xp * sn[angle]) >> 8) );
  1071.     zv    =    (long)(sn[angle] + ((xp * cs[angle]) >> 8) );
  1072.  
  1073.     yv    =    yp - yOffSet - (xOffSet >> 8);
  1074.     yOffSet2 = - yOffSet - xOffSetdiv;
  1075.  
  1076.     rayLenTmp = 128;
  1077.     if (rayLen < rayLenTmp) rayLenTmp = rayLen;
  1078.     MrBlobby = mrBlob1;
  1079.  
  1080.     while (L<rayLenTmp)
  1081.         {                        
  1082.     
  1083.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  1084.             {
  1085.             *(long*)(offScreen2) = 
  1086.             *(long*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  1087.  
  1088.             yp += yStep;
  1089.             if (yp >= windY) goto end3;    
  1090.     
  1091.             offScreen2    -= windXstep;
  1092.             yv += yStep;
  1093.  
  1094.             z = hhhh + (yv * L);
  1095.  
  1096.             }
  1097.             else
  1098.             {
  1099.                 L++;
  1100.                 z += yv;
  1101.                 x += xv;
  1102.                 y += zv;
  1103.                 MrBlobby = mrBlob1;
  1104.             }
  1105.         }
  1106.         
  1107.         yv    =    yv << 1;
  1108.         xv    =    xv << 1;
  1109.         zv    =    zv << 1;
  1110.         
  1111.         rayLenTmp = 256;
  1112.         if (rayLen < rayLenTmp) rayLenTmp = rayLen;
  1113.         
  1114.         if (yp>=windY) L = rayLenTmp;
  1115.  
  1116.         yztemp = yp + yOffSet2;
  1117.  
  1118.         while ( L < rayLenTmp )
  1119.         {
  1120.  
  1121.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  1122.             {
  1123.             *(unsigned long*)(offScreen2) = 
  1124.             *(unsigned long*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  1125.             
  1126.             yp    += yStep;
  1127.             if (yp >= windY) goto end3;
  1128.                         
  1129.             offScreen2    -= windXstep;
  1130.  
  1131.             yztemp += yStep;
  1132.             yv = yztemp << 1;
  1133.             
  1134.             z = hhhh + (yztemp * L);
  1135.  
  1136.             }
  1137.             else
  1138.             {
  1139.                 L += 2;
  1140.                 x += xv;
  1141.                 y += zv;
  1142.                 z += yv;
  1143.                 MrBlobby = mrBlob2;
  1144.             }
  1145.         }
  1146.         
  1147.         yv    =    yv << 1;
  1148.         xv    =    xv << 1;
  1149.         zv    =    zv << 1;
  1150.         
  1151.         rayLenTmp = rayLen;
  1152.         
  1153.         if (yp>=windY) goto end3;
  1154.         
  1155.         yztemp = yp + yOffSet2;
  1156.  
  1157.         while (L<rayLenTmp)
  1158.         {
  1159.  
  1160.         if ( *(unsigned char*)(theTemp + MrBlobby ) > (z >> heightShift) )
  1161.             {
  1162.             *(unsigned long*)(offScreen2) = 
  1163.             *(unsigned long*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
  1164.             
  1165.             yp += yStep;
  1166.             if (yp >= windY) goto end3;
  1167.             
  1168.             offScreen2    -= windXstep;
  1169.                         
  1170.             yztemp += yStep;
  1171.             yv    =    yztemp << 2;
  1172.             
  1173.             z = hhhh + (yztemp * L);
  1174.             }
  1175.             else
  1176.             {
  1177.                 L += 4;
  1178.                 x += xv;
  1179.                 y += zv;
  1180.                 z += yv;
  1181.                 MrBlobby = mrBlob3;
  1182.             }
  1183.         }
  1184.  
  1185.     end3:
  1186.     xp2    += 4;
  1187.     xp    += 4;
  1188.     xOffSet += xChng;
  1189.     xOffSetdiv = xOffSet >> 8;
  1190.     }
  1191.  
  1192.     copyOffScreen();
  1193.     clearOffScreen();
  1194. }
  1195.  
  1196. void DoPreferences(void)
  1197. {
  1198. Boolean         itsDone;
  1199. DialogPtr        theDialog, theDialog2;
  1200. short            itemHit, itemHit2;
  1201. Rect            iRect;
  1202. Point             tempPoint;
  1203. Rect            tempRect;
  1204. StringHandle    string;
  1205.  
  1206. short            WindowSizeError, WindowSizeTemp;
  1207. short            PixelSizeError, PixelSizeTemp;
  1208. short            LandScapeError, LandScapeTemp;
  1209. short            RayLenError, RayLenTemp;
  1210. short            keyBoardTemp, keyBoardError;
  1211. short            heightTemp, heightError;
  1212. short            roughTemp, roughError;
  1213.  
  1214. ControlHandle    WindSizeCtrl, PixSizeCtrl, LandCtrl, RayLenCtrl, ctrlCtrl, heightCtrl, roughCtrl;
  1215. MenuHandle        WindSizeMenu, LandMenu, PixSizeMenu, RayLenMenu, ctrlMenu, heightMenu, roughMenu;
  1216.  
  1217. ShowCursor();
  1218.  
  1219. string = NewHandle( 256 );
  1220.  
  1221. theDialog = GetNewDialog(133, nil, BackWindow);
  1222.  
  1223. if (theDialog == 0) DoError(4 ,TRUE);
  1224.  
  1225. SetPort( theDialog );
  1226.  
  1227. SelectWindow( theDialog );
  1228. BringToFront( theDialog );
  1229. DrawDialog( theDialog );
  1230.  
  1231. PenMode( 0 );
  1232. PenSize( 3, 3 );
  1233. tempRect = GetDRect( theDialog, 21 );
  1234. FrameRoundRect( &tempRect, 16, 16 );
  1235.  
  1236. tempRect = GetDRect(theDialog, mWindSize);
  1237. WindSizeCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, WindSizeMnu, 0, (1008 + 5), WindSizeMnu);
  1238. if (WindSizeCtrl == 0) DoError(18 ,TRUE);
  1239.  
  1240. WindSizeMenu = GetMenu(WindSizeMnu);
  1241. if (WindSizeMenu == 0) DoError(1 ,TRUE);
  1242. InsertMenu(WindSizeMenu, -1);
  1243.  
  1244. tempRect = GetDRect(theDialog, mHeight);
  1245. heightCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, heightMnu, 0, (1008 + 5), WindSizeMnu);
  1246. if (heightCtrl == 0) DoError(18 ,TRUE);
  1247.  
  1248. heightMenu = GetMenu(heightMnu);
  1249. if (heightMenu == 0) DoError(1 ,TRUE);
  1250. InsertMenu(heightMenu, -1);
  1251.  
  1252. tempRect = GetDRect(theDialog, mRough);
  1253. roughCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, roughMnu, 0, (1008 + 5), WindSizeMnu);
  1254. if (roughCtrl == 0) DoError(18 ,TRUE);
  1255.  
  1256. roughMenu = GetMenu(roughMnu);
  1257. if (roughMenu == 0) DoError(1 ,TRUE);
  1258. InsertMenu(roughMenu, -1);
  1259.  
  1260. tempRect = GetDRect( theDialog, mCtrl );
  1261. ctrlCtrl = NewControl( theDialog, &tempRect, "", TRUE, 1, CtrlMnu, 0, (1008 + 5), WindSizeMnu );
  1262. if (ctrlCtrl == 0) DoError(18 ,TRUE);
  1263.  
  1264. ctrlMenu = GetMenu( CtrlMnu );
  1265. if ( ctrlMenu == 0 ) DoError( 1 ,TRUE );
  1266. InsertMenu(ctrlMenu, -1);
  1267.  
  1268. if (theScreen.resolutionX < 640) DisableItem(WindSizeMenu, 6);
  1269. if (theScreen.resolutionX < 640) DisableItem(WindSizeMenu, 5);
  1270. if (theScreen.resolutionX < 512) DisableItem(WindSizeMenu, 4);
  1271. if (theScreen.resolutionX < 400) DisableItem(WindSizeMenu, 3);
  1272. if (theScreen.resolutionX < 320) DisableItem(WindSizeMenu, 2);
  1273. if (theScreen.resolutionX < 160) DisableItem(WindSizeMenu, 1);
  1274.  
  1275. if (theScreen.resolutionY < 480) DisableItem(WindSizeMenu, 6);
  1276. if (theScreen.resolutionY < 400) DisableItem(WindSizeMenu, 5);
  1277. if (theScreen.resolutionY < 384) DisableItem(WindSizeMenu, 4);
  1278. if (theScreen.resolutionY < 300) DisableItem(WindSizeMenu, 3);
  1279. if (theScreen.resolutionY < 240) DisableItem(WindSizeMenu, 2);
  1280. if (theScreen.resolutionY < 120) DisableItem(WindSizeMenu, 1);
  1281.  
  1282. tempRect = GetDRect(theDialog, mPixelSize);
  1283. PixSizeCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, PixSizeMnu, 0, (1008 + 5), WindSizeMnu);
  1284. if (PixSizeCtrl == 0) DoError(18 ,TRUE);
  1285.  
  1286. PixSizeMenu = GetMenu(PixSizeMnu);
  1287. if (PixSizeMenu == 0) DoError(1 ,TRUE);
  1288. InsertMenu(PixSizeMenu, -1);
  1289.  
  1290. tempRect = GetDRect(theDialog, mLandscape);
  1291. LandCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, LandMnu, 0, (1008 + 5), WindSizeMnu);
  1292. if (LandCtrl == 0) DoError(18 ,TRUE);
  1293.  
  1294. LandMenu = GetMenu(LandMnu);
  1295. if (LandMenu == 0) DoError(1 ,TRUE);
  1296. InsertMenu(LandMenu, -1);
  1297.  
  1298. tempRect = GetDRect(theDialog, mRayLength);
  1299. RayLenCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, RayLenMnu, 0, (1008 + 5), WindSizeMnu);
  1300. if (RayLenCtrl == 0) DoError(18 ,TRUE);
  1301.  
  1302. RayLenMenu = GetMenu(RayLenMnu);
  1303. if (RayLenMenu == 0) DoError(1 ,TRUE);
  1304. InsertMenu(RayLenMenu, -1);
  1305.  
  1306. SetTheInfo(theDialog, tRandSeed, randSeed);
  1307. SetTheInfo(theDialog, tWaterLevel, waterLevel);
  1308.  
  1309. SetCtlValue( PixSizeCtrl , (short)PixelSizeOption );
  1310. SetCtlValue( WindSizeCtrl, (short)WindowSizeOption );
  1311. SetCtlValue( LandCtrl    , (short)LandScapeOption );
  1312. SetCtlValue( RayLenCtrl  , (short)RayLengthOption );
  1313. SetCtlValue( ctrlCtrl    , (short)keyBoard );
  1314. SetCtlValue( heightCtrl  , (short)maxHeight );
  1315. SetCtlValue( roughCtrl   , (short)roughness );
  1316.  
  1317. tempRect = GetDRect( theDialog, 24);
  1318. FrameRect(&tempRect);
  1319. tempRect = GetDRect( theDialog, 29);
  1320. FrameRect(&tempRect);
  1321.  
  1322. itsDone = FALSE;
  1323.  
  1324. FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  1325.  
  1326.     while(!itsDone)
  1327.     {
  1328.         ModalDialog(nil, &itemHit);
  1329.         if (itemHit == bOK)     {
  1330.                                 itsDone = TRUE;
  1331.                                 }
  1332.         
  1333.         if (itemHit == bQuit)     {
  1334.                                 Quit();
  1335.                                 }
  1336.  
  1337.         if (itemHit == bAbout)     {
  1338.                                 FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  1339.                                 theDialog2 = GetNewDialog(8000, nil, BackWindow);
  1340.                                 SelectWindow(theDialog2);
  1341.                                 BringToFront(theDialog2);
  1342.                                 SetPort( theDialog2 );
  1343.                                 PenMode( 0 );
  1344.                                 PenSize( 3, 3 );
  1345.                                 tempRect = GetDRect( theDialog2, 4 );
  1346.                                 FrameRoundRect( &tempRect, 16, 16 );
  1347.                                 itemHit2 = 0;
  1348.                                 while(itemHit2 != 1) { ModalDialog(nil, &itemHit2); }
  1349.                                 DisposDialog(theDialog2);
  1350.                                 SetPort( theDialog );
  1351.                                 FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  1352.                                 tempRect = GetDRect( theDialog, 24);
  1353.                                 FrameRect(&tempRect);
  1354.                                 tempRect = GetDRect( theDialog, 29);
  1355.                                 FrameRect(&tempRect);
  1356.                                 }
  1357.  
  1358.         if (itemHit == bRandomize){
  1359.                                 qd.randSeed = (unsigned long)TickCount();
  1360.                                 randSeed = Random() + 32767;
  1361.                                 if (randSeed == 0) randSeed = 1;
  1362.                                 SetTheInfo(theDialog, tRandSeed, randSeed);
  1363.                                 }
  1364.  
  1365.         if (itemHit == mWindSize){
  1366.                                     WindowSizeError = WindowSizeOption;
  1367.                                     iRect = GetDRect(theDialog, mWindSize);
  1368.                                     tempPoint.v = iRect.top;
  1369.                                     tempPoint.h = iRect.left;
  1370.                                     LocalToGlobal(&tempPoint);
  1371.                                     WindowSizeTemp = PopUpMenuSelect(WindSizeMenu, tempPoint.v, tempPoint.h, WindowSizeOption);
  1372.                                     if (WindowSizeTemp != 0) WindowSizeOption = WindowSizeTemp;
  1373.                                     if (WindowSizeTemp == 8) {
  1374.                                                                 DoOther();
  1375.                                                                 SetPort(theDialog);
  1376.                                                                 tempRect = GetDRect( theDialog, 18);
  1377.                                                                 FrameRect(&tempRect);
  1378.                                                              }
  1379.                                     SetCtlValue(WindSizeCtrl, (short)WindowSizeOption);
  1380.                                 }
  1381.  
  1382.         if (itemHit == mPixelSize){
  1383.                                     PixelSizeError = PixelSizeOption;
  1384.                                     iRect = GetDRect(theDialog, mPixelSize);
  1385.                                     tempPoint.v = iRect.top;
  1386.                                     tempPoint.h = iRect.left;
  1387.                                     LocalToGlobal(&tempPoint);
  1388.                                     PixelSizeTemp = PopUpMenuSelect(PixSizeMenu, tempPoint.v, tempPoint.h, PixelSizeOption);
  1389.                                     if (PixelSizeTemp != 0) PixelSizeOption = PixelSizeTemp;
  1390.                                     SetCtlValue(PixSizeCtrl, (short)PixelSizeOption);
  1391.                                 }
  1392.  
  1393.         if (itemHit == mCtrl){
  1394.                                     keyBoardError = keyBoard;
  1395.                                     iRect = GetDRect(theDialog, mCtrl);
  1396.                                     tempPoint.v = iRect.top;
  1397.                                     tempPoint.h = iRect.left;
  1398.                                     LocalToGlobal(&tempPoint);
  1399.                                     keyBoardTemp = PopUpMenuSelect( ctrlMenu, tempPoint.v, tempPoint.h, keyBoard);
  1400.                                     if (keyBoardTemp != 0) keyBoard = keyBoardTemp;
  1401.                                     SetCtlValue(ctrlCtrl, (short)keyBoard);
  1402.                                 }
  1403.  
  1404.         if (itemHit == mHeight){
  1405.                                     heightError = maxHeight;
  1406.                                     iRect = GetDRect(theDialog, mHeight);
  1407.                                     tempPoint.v = iRect.top;
  1408.                                     tempPoint.h = iRect.left;
  1409.                                     LocalToGlobal(&tempPoint);
  1410.                                     heightTemp = PopUpMenuSelect( heightMenu, tempPoint.v, tempPoint.h, maxHeight );
  1411.                                     if (heightTemp != 0) maxHeight = heightTemp;
  1412.                                     SetCtlValue(heightCtrl, (short)maxHeight);
  1413.                                 }
  1414.  
  1415.         if (itemHit == mRough){
  1416.                                     roughError = roughness;
  1417.                                     iRect = GetDRect(theDialog, mRough);
  1418.                                     tempPoint.v = iRect.top;
  1419.                                     tempPoint.h = iRect.left;
  1420.                                     LocalToGlobal(&tempPoint);
  1421.                                     roughTemp = PopUpMenuSelect( roughMenu, tempPoint.v, tempPoint.h, roughness );
  1422.                                     if (roughTemp != 0) roughness = roughTemp;
  1423.                                     SetCtlValue(roughCtrl, (short)roughness);
  1424.                                 }
  1425.  
  1426.         if (itemHit == mLandscape){
  1427.                                     LandScapeError = LandScapeOption;
  1428.                                     iRect = GetDRect(theDialog, mLandscape);
  1429.                                     tempPoint.v = iRect.top;
  1430.                                     tempPoint.h = iRect.left;
  1431.                                     LocalToGlobal(&tempPoint);
  1432.                                     LandScapeTemp = PopUpMenuSelect(LandMenu, tempPoint.v, tempPoint.h, LandScapeOption);
  1433.                                     if (LandScapeTemp != 0) LandScapeOption = LandScapeTemp;
  1434.                                     SetCtlValue(LandCtrl, (short)LandScapeOption);
  1435.                                 }
  1436.  
  1437.         if (itemHit == mRayLength){
  1438.                                     RayLenError = RayLengthOption;
  1439.                                     iRect = GetDRect(theDialog, mRayLength);
  1440.                                     tempPoint.v = iRect.top;
  1441.                                     tempPoint.h = iRect.left;
  1442.                                     LocalToGlobal(&tempPoint);
  1443.                                     RayLenTemp = PopUpMenuSelect(RayLenMenu, tempPoint.v, tempPoint.h, RayLengthOption);
  1444.                                     if (RayLenTemp != 0) RayLengthOption = RayLenTemp;
  1445.                                     SetCtlValue(RayLenCtrl, (short)RayLengthOption);
  1446.                                 }
  1447.     }
  1448.  
  1449. GetTheInfoStr(theDialog, tRandSeed, string);
  1450. StringToNum(*string, &randSeed);
  1451.  
  1452. GetTheInfoStr(theDialog, tWaterLevel, string);
  1453. StringToNum(*string, &waterLevel);
  1454.  
  1455. if (randSeed == 0) randSeed = 1;
  1456.  
  1457. tempPoint.v = 0;
  1458. tempPoint.h = 0;
  1459. ShieldCursor(&theScreen.screenRect, tempPoint);
  1460.  
  1461. DisposHandle(string);
  1462.  
  1463. switch (WindowSizeOption) {
  1464.  
  1465.                 case 1:    {    windX = 80;
  1466.                             windY = 60;
  1467.                         }     break;
  1468.  
  1469.                 case 2:    {    windX = 160;
  1470.                             windY = 120;
  1471.                         }     break;
  1472.  
  1473.                 case 3:    {    windX = 200;
  1474.                             windY = 150;
  1475.                         }     break;
  1476.  
  1477.                 case 4:    {    windX = 256;
  1478.                             windY = 192;
  1479.                         }     break;
  1480.  
  1481.                 case 5:    {    windX = 320;
  1482.                             windY = 200;
  1483.                         }     break;
  1484.  
  1485.                 case 6:    {    windX = 320;
  1486.                             windY = 240;
  1487.                         }     break;
  1488.                         
  1489.                         }
  1490.  
  1491. switch (PixelSizeOption) {
  1492.  
  1493.                 case 1:    {    xStep = 1;
  1494.                             yStep = 1;
  1495.                         }     break;
  1496.  
  1497.                 case 2:    {    xStep = 2;
  1498.                             yStep = 1;
  1499.                         }     break;
  1500.  
  1501.                 case 3:    {    xStep = 2;
  1502.                             yStep = 2;
  1503.                         }     break;
  1504.  
  1505.                 case 4:    {    xStep = 4;
  1506.                             yStep = 2;
  1507.                         }     break;
  1508.  
  1509.                 case 5:    {    xStep = 4;
  1510.                             yStep = 4;
  1511.                         }     break;
  1512.                         
  1513.                         }
  1514.                         
  1515. switch (RayLengthOption) {
  1516.  
  1517.                 case 1:    {    rayLen = 128;
  1518.                         }     break;
  1519.  
  1520.                 case 2:    {    rayLen = 200;
  1521.                         }     break;
  1522.  
  1523.                 case 3:    {    rayLen = 256;
  1524.                         }     break;
  1525.  
  1526.                 case 4:    {    rayLen = 320;
  1527.                         }     break;
  1528.  
  1529.                 case 5:    {    rayLen = 400;
  1530.                         }     break;
  1531.  
  1532.                 case 6:    {    rayLen = 512;
  1533.                         }     break;
  1534.  
  1535.                         }
  1536. pNum = LandScapeOption;
  1537.  
  1538. DisposDialog(theDialog);
  1539. FillWindowsBlack( );
  1540. }
  1541.  
  1542. void DoOther(void)
  1543. {
  1544. DialogPtr    dialog;
  1545. short    itemHit;
  1546. Boolean itsDone;
  1547. short    windXtemp, windYtemp;
  1548. Rect    theRect;
  1549.  
  1550. FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  1551.  
  1552. dialog = GetNewDialog(128, nil, BackWindow);
  1553. if (dialog == 0) DoError(4 ,TRUE);
  1554.  
  1555. SetTheInfo(dialog, 3, windX2);
  1556. SetTheInfo(dialog, 4, windY2);
  1557. SelectWindow(dialog);
  1558.  
  1559. BringToFront( dialog );
  1560. DrawDialog( dialog );
  1561. SetPort( dialog );
  1562.  
  1563. PenMode( 0 );
  1564. PenSize( 3, 3 );
  1565. theRect = GetDRect( dialog, 6 );
  1566. FrameRoundRect( &theRect, 16, 16 );
  1567.  
  1568. itsDone = FALSE;
  1569.  
  1570. while(itsDone != TRUE) {
  1571.  
  1572. ModalDialog(nil, &itemHit);
  1573.  
  1574.     switch (itemHit) {
  1575.     
  1576.                     case bOK:    {
  1577.                                     windXtemp = GetTheInfo(dialog, 3);
  1578.                                     if (windXtemp > theScreen.resolutionX) windXtemp = theScreen.resolutionX;
  1579.                                     windYtemp = GetTheInfo(dialog, 4);
  1580.                                     if (windYtemp > theScreen.resolutionY) windYtemp = theScreen.resolutionY;
  1581.                                     windXtemp = windXtemp >> 5 << 5;
  1582.                                     windYtemp = windYtemp >> 2 << 2;
  1583.                                     if (windXtemp == 0) windXtemp = 32;
  1584.                                     if (windYtemp == 0) windYtemp = 32;
  1585.                                     windX = windXtemp >> 1;
  1586.                                     windY = windYtemp >> 1;
  1587.                                     itsDone = TRUE;
  1588.                                 }
  1589.             
  1590.                     case bQuit: {
  1591.                                     itsDone = TRUE;
  1592.                                 }
  1593.                     }
  1594. }
  1595.  
  1596. DisposDialog(dialog);
  1597. FillWindowsBlack( );
  1598. FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  1599. }
  1600.  
  1601. void Quit(void)
  1602. {
  1603.     ShowCursor();
  1604.     ShowMenuBar();
  1605.     MemEnd();
  1606.     FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
  1607.     ChangeBitDepth(oldBitDepth,1);
  1608.     ExitToShell();
  1609. }